package Package.Reflection.MethodOfTheClassGetsTheMemberMethodObject;

import java.lang.reflect.Constructor;
import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.Arrays;

public class MethodOfTheClassGetsTheMemberMethodObject {
    public static final void MethodOfTheClassGetsTheMemberMethodObject() throws ClassNotFoundException, NoSuchMethodException, InvocationTargetException, InstantiationException, IllegalAccessException, NoSuchFieldException {
//方法名 说明
//Method[] getMethods() 返回所有公共成员方法对象的数组，包括继承的
        Class<?> c=Class.forName("Package.Example.GetsTheConstructorAndUses.Student");
        Method[] methods=c.getMethods();
        System.out.println("+++++++++++++++++++++++++++++++++++++++++");
        Arrays.stream(methods).forEach(System.out::println);
        //Method[] getDeclaredMethods() 返回所有成员方法对象的数组，不包括继承的
        Method[] methods1=c.getDeclaredMethods();
        System.out.println("+++++++++++++++++++++++");
        Arrays.stream(methods1).forEach(System.out::println);
//Method getMethod(String name, Class<?>...parameterTypes)返回单个公共成员方法对象
        Method method = c.getMethod("getClass");
        System.out.println("++++++++++++++++++++++++++++");
        System.out.println(method);
//Method getDeclaredMethod(String name, Class<?>...parameterTypes)返回单个成员方法对象

        Method declaredMethod = c.getDeclaredMethod("toString");
        System.out.println(declaredMethod);
//        Objectinvoke(Object obj,Object... args) 调用obj对象的成员方法，参数是args,返回值是Object类型
        Constructor<?> com=c.getConstructor();
        Object obj=com.newInstance();
        com.setAccessible(true);
        Field getAddresses=c.getDeclaredField("address");
        getAddresses.set(obj,"uifweqrhguj");
        System.out.println("_______________________________)))))))))))))))))");

        System.out.println(declaredMethod.invoke(obj));
    }
}
